from selenium import webdriver
from selenium.webdriver.common.by import By
import time


class TestCase:
    # 初始化打开Chrome浏览器
    def __init__(self):
        self.driver = webdriver.Chrome()

    # 百度
    def baidu(self):
        # 打开百度
        self.driver.get('https://www.baidu.com')
        # 输入关键字‘天气’
        self.driver.find_element(By.ID, 'kw').send_keys('天气')
        # 点击百度按钮
        self.driver.find_element(By.ID, 'su').click()
        # 打印标题
        time.sleep(2)
        print(self.driver.title)
        # 判断‘python’是否在标题中
        if 'python' in self.driver.title:
            print(1)
        else:
            print(0)

    # sogou
    def sogou(self):
        # 打开搜狗搜索
        self.driver.get('https://www.sogou.com')
        # 定位搜索框，输入关键字’天气‘
        self.driver.find_element(By.ID, 'query').send_keys('天气')
        # 定位搜索按钮，并点击
        self.driver.find_element(By.ID, 'stb').click()
        # 打印标题
        time.sleep(2)
        print(self.driver.title)
        # 判断’python‘是否在标题中
        if 'python' in self.driver.title:
            print(1)
        else:
            print(0)

    # 关闭浏览器
    def quit(self):
        time.sleep(2)
        self.driver.quit()



class TestCase1:
    # 初始化打开Chrome浏览器
    def __init__(self):
        self.driver = webdriver.Chrome()

    # 百度
    def baidu(self):
        # 打开百度
        self.driver.get('https://www.baidu.com')
        # 输入关键字‘天气’
        self.driver.find_element(By.ID, 'kw').send_keys('天气')
        # 点击百度按钮
        self.driver.find_element(By.ID, 'su').click()
        # 打印标题
        time.sleep(2)
        print(self.driver.title)
        # 判断‘python’是否在标题中
        if 'python' in self.driver.title:
            print(1)
        else:
            print(0)

    # sogou
    def sogou(self):
        # 打开搜狗搜索
        self.driver.get('https://www.sogou.com')
        # 定位搜索框，输入关键字’天气‘
        self.driver.find_element(By.ID, 'query').send_keys('天气')
        # 定位搜索按钮，并点击
        self.driver.find_element(By.ID, 'stb').click()
        # 打印标题
        time.sleep(2)
        print(self.driver.title)
        # 判断’python‘是否在标题中
        if 'python' in self.driver.title:
            print(1)
        else:
            print(0)

    # 关闭浏览器
    def quit(self):
        self.driver.quit()


class Testcase2:
    # 初始化打开Chrome浏览器
    def __init__(self):
        self.driver = webdriver.Chrome()
    # 百度
    def baidu(self):
        # 打开百度
        self.driver.get('https://www.baidu.com')
        # 输入关键字‘天气’
        self.driver.find_element(By.ID, 'kw').send_keys('天气')
        # 点击百度按钮
        self.driver.find_element(By.ID, 'su').click()
        # 打印标题
        time.sleep(2)
        print(self.driver.title)
        # 判断‘python’是否在标题中
        if 'python' in self.driver.title:
            print(1)
        else:
            print(0)

    # sogou
    def sogou(self):
        # 打开搜狗搜索
        self.driver.get('https://www.sogou.com')
        # 定位搜索框，输入关键字’天气‘
        self.driver.find_element(By.ID, 'query').send_keys('天气')
        # 定位搜索按钮，并点击
        self.driver.find_element(By.ID, 'stb').click()
        # 打印标题
        time.sleep(2)
        print(self.driver.title)
        # 判断’python‘是否在标题中
        if 'python' in self.driver.title:
            print(1)
        else:
            print(0)

    # 关闭浏览器
    def quit(self):
        time.sleep(2)
        self.driver.quit()

if __name__ == '__main__':
    b = Testcase2()
    b.baidu()
    b.sogou()
    b.quit()